package repo

import (
	"gitee.com/tietang/terrace-go/v2/example/order"
	"gitee.com/tietang/terrace-go/v2/example/order/domain"
)

var _ domain.OrderRepository = new(OrderImMemRepository)

type OrderImMemRepository struct {
	repo map[string]*order.Order
}

func (o *OrderImMemRepository) Get(id int64) *order.Order {
	panic("implement me")
}

func (o *OrderImMemRepository) Save(order order.Order) (id int64, err error) {
	o.repo[order.TradeNo] = &order
	return 1, nil
}
func (o *OrderImMemRepository) UpdateStatus(order order.Order) (id int64, err error) {
	old, ok := o.repo[order.TradeNo]
	if ok {
		old.Status = order.Status
		return 1, nil
	}
	return 0, nil
}

func (o *OrderImMemRepository) GetOne(tradeNo string) *order.Order {
	old, ok := o.repo[tradeNo]
	if ok {
		return old
	}
	return nil
}
